<template>
  <el-tag v-if="text" effect="plain" type="success">{{ text }}</el-tag>
</template>

<script setup>
import { ref, watch } from "vue";
import { getDictTag } from "@/utils/dict";

defineOptions({
  name: "DictTag"
});

// 传值
const props = defineProps({
  dictType: {
    type: String,
    required: true
  },
  dictValue: {
    required: true
  }
});

const text = ref("");
const dataList = JSON.parse(localStorage.getItem("dictList")) || [];

watch(
  () => props.dictValue,
  async newValue => {
    text.value = getDictTag(dataList, props.dictType, props.dictValue);
  },
  { immediate: true }
);
</script>

<style lang="scss" scoped></style>
